Project_2

저자

Choi Pro


아래는 R을 이용한 데이터 전처리 예제입니다. 문제와 답만 있습니다. 풀이 과정을 코드로 제출하세요. 제출 결과에 따라 다음 과정의 Project 3 난이도 조정이 됩니다.

신뢰성 평가 결과 데이터 셋 다운로드

OLED 패널의 신뢰성 평가 결과 데이터이다.

** Reliability Test Split Conditions**

Test Type Description Test Condition
HTS High Temperature Storage 85℃, 500h/1000h
T/C Temperature Cycle -30℃(1h) ↔︎ 85℃(1h), 500h/1000h
THS Temperature Humidity Storage 60℃/90%RH, 500h/1000h
T/S Thermal Shock -45℃(30min) ↔︎ 85℃(30min), 500h/1000h

이 신뢰성 평가는 다음과 같은 주요 변수들로 구성되어 있습니다:

코드
library(patchwork)
library(corrplot)

난이도 하


문제 1: Test_type별 Pass/Fail 의 샘플 수를 보여라.

단계별 요구사항

  • 필수 패키지 로드
library(tidyverse)
library(plotly)
library(showtext)
showtext.auto()
코드
library(tidyverse)
library(plotly)
library(showtext)
showtext.auto()


  • df 변수에 reliability_test.csv 를 불러와서 넣는다.(read.csv)
  • 앞 행 6개를 표시한다. (head)
코드
df <- read.csv("./data/reliability_test.csv")

head(df)
  Test_type         Panel Test_duration Result Sample_count
1       HTS Flexible_OLED         1000h   Fail            4
2       HTS Flexible_OLED         1000h   Pass          199
3       HTS Flexible_OLED          500h   Fail            0
4       HTS Flexible_OLED          500h   Pass          140
5       HTS    Rigid_OLED         1000h   Fail          118
6       HTS    Rigid_OLED         1000h   Pass            5


  • Test 종류별 Pass/Fail 수를 보여준다.
코드
df |> 
  group_by(Test_type, Result) |>
  summarise(샘플수 = sum(Sample_count ))
# A tibble: 8 × 3
# Groups:   Test_type [4]
  Test_type Result 샘플수
  <chr>     <chr>   <int>
1 HTS       Fail      122
2 HTS       Pass      401
3 TC        Fail      167
4 TC        Pass      271
5 THS       Fail      528
6 THS       Pass      602
7 TS        Fail      101
8 TS        Pass      622


  • 이 결과를 막대 그래프로 시각화를 하라. (개별 그래프)
코드
p1 <- df |> 
  group_by(Test_type, Result) |>
  summarise(샘플수 = sum(Sample_count )) |> 
  ggplot(aes(x=Test_type, y=샘플수, fill=Result))+
 geom_bar(stat = "identity", position = "dodge") 

ggplotly(p1)


  • 각 막대 그래프에 샘플수를 text로 표시하라.
코드
p2 <- df |> 
  group_by(Test_type, Result) |>
  summarise(샘플수 = sum(Sample_count )) |> 
  ggplot(aes(x=Test_type, y=샘플수, fill=Result))+
  geom_bar(stat = "identity", position = "dodge")+
  geom_text(aes(label = 샘플수), position = position_dodge(0.9),
            vjust = -0.5) 

ggplotly(p2)


  • 그래프 제목 (“신뢰성 종류별 Pass/Fail 샘플수”), X축(“신뢰성 평가 종류”), Y축(“샘플수”) 를 표시하라.
코드
p3 <- df |> 
  group_by(Test_type, Result) |>
  summarise(샘플수 = sum(Sample_count )) |> 
  ggplot(aes(x=Test_type, y=샘플수, fill=Result))+
  geom_bar(stat = "identity", position = "dodge")+
  geom_text(aes(label = 샘플수), position = position_dodge(0.9),
            vjust = -0.5) +
  labs(title = "신뢰성 종류별 Pass/Fail 샘플수",
       x="신뢰성 평가 종류",
       y="샘플수")

ggplotly(p3)




난이도 중


문제 2: Test_duration별 Pass/Fail 시각화하시오

단계별 요구사항

  • HTS 와 THS의 신뢰성 평가에서 Test 시간에 따른 Rigid 패널과 Flexible 패널의 양품율을 보이시오 양품율 = Pass 샘플수 / (Pass 샘플수 + Fail 샘플수) * 100
코드
table1 <- df |> 
  filter(Test_type %in% c("HTS", "THS")) |> 
  filter(Result =="Fail") |> 
  group_by(Test_type,Panel, Test_duration) |> 
  summarise(n_Fail = sum(Sample_count))

table2 <- df |> 
  filter(Test_type %in% c("HTS", "THS")) |> 
  filter(Result =="Pass") |> 
  group_by(Test_type,Panel, Test_duration) |> 
  summarise(n_Pass = sum(Sample_count))



table3 <- left_join(table1,table2) |> 
  mutate(양품율 = round(n_Pass/(n_Pass + n_Fail)*100,1))
  
table3
# A tibble: 8 × 6
# Groups:   Test_type, Panel [4]
  Test_type Panel         Test_duration n_Fail n_Pass 양품율
  <chr>     <chr>         <chr>          <int>  <int>  <dbl>
1 HTS       Flexible_OLED 1000h              4    199   98  
2 HTS       Flexible_OLED 500h               0    140  100  
3 HTS       Rigid_OLED    1000h            118      5    4.1
4 HTS       Rigid_OLED    500h               0     57  100  
5 THS       Flexible_OLED 1000h             89     14   13.6
6 THS       Flexible_OLED 500h              17    500   96.7
7 THS       Rigid_OLED    1000h            387     13    3.2
8 THS       Rigid_OLED    500h              35     75   68.2
  • 그룹화된 막대 그래프 사용하여 시각화 하시오. (x축은 Test_duration, y축은 양품율, Panel종류에 따라 색 구별, facet_wrap 은 Test_type)
코드
p <- table3 |> 
  ggplot(aes(x = Test_duration, y =양품율, fill = Panel)) +
  geom_bar(stat = "identity", position = "dodge")+
  facet_wrap(~Test_type)
  
ggplotly(p)
  • x축에 500h, 1000h 순서로 나열 (fct_reorder)
코드
p <- table3 |> 
  mutate(Test_duration = fct_reorder(Test_duration, -양품율)) |> 
  ggplot(aes(x = Test_duration, y =양품율, fill = Panel)) +
  geom_bar(stat = "identity", position = "dodge")+
  facet_wrap(~Test_type)
  
ggplotly(p)
  • x축 이름: 테스트 시간(h), y축 이름: 양품율(%), 제목 : 테스트 조건별 양품율, theme_bw() 적용
코드
p <- table3 |> 
  mutate(Test_duration = fct_reorder(Test_duration, -양품율)) |> 
  ggplot(aes(x = Test_duration, y =양품율, fill = Panel)) +
  geom_bar(stat = "identity", position = "dodge")+
  geom_text(aes(label = 양품율), position = position_dodge(0.9),  vjust = -0.5) +
  facet_wrap(~Test_type)+
  labs(title = "테스트 조건별 양품율",
       x = "테스트 시간(h)",
       y = "양품율(%)",
       fill = "결과") +
  theme_bw()
  
ggplotly(p)


난이도 상

3. 신뢰성 종류별 투입한 Panel_type 분포를 시각화하시오.

단계별 요구사항

  • Flexible 패널에서 신뢰성 조건별 1000h 데이터로 기술 통계(summaris)
코드
table <- df |> 
  filter(Panel == "Flexible_OLED", Test_duration=="1000h") |> 
  group_by(Test_type, Result) |> 
  summarise(n = sum(Sample_count)) 

table
# A tibble: 8 × 3
# Groups:   Test_type [4]
  Test_type Result     n
  <chr>     <chr>  <int>
1 HTS       Fail       4
2 HTS       Pass     199
3 TC        Fail      13
4 TC        Pass      40
5 THS       Fail      89
6 THS       Pass      14
7 TS        Fail       3
8 TS        Pass      70
  • 테스트 조건별 Pass, Fail 비율 표시하기
코드
 table2 <- table |> 
  # 비율 계산 추가
  group_by(Test_type) |> 
  mutate(percentage = round(n/sum(n)*100, 1)) 

-geom_tile 그래프로 그리기 (x축: Result, y축: Test_type, fill: percentage )

코드
p1 <- table2 |> 
  ggplot(aes(x = Result, y = Test_type, fill = percentage)) +
  geom_tile(color = "white")
  • color를 gradient하게 바꾸고 theme_minimal, 적절한 제목을 달아라.